<%@ page import="com.ws.lv.util.Res" %><%--
  Created by IntelliJ IDEA.
  User: Adminis
  Date: 2025/3/20
  Time: 09:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>线路管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/bootstrap.min.css">
    <script src="${pageContext.request.contextPath}/admin/js/jquery-2.1.0.min.js"></script>
    <script src="${pageContext.request.contextPath}/admin/js/bootstrap.min.js"></script>
    <style>

        .cus-container {
            width: 1368px;
        }

        #user-add .modal-content {
            padding: 0 20px 20px;
        }

        #user-edit .modal-content {
            padding: 0 20px 20px;
        }

        #user-list td {
            vertical-align: middle;
        }

        b {
            color: red;
        }

        .zhuTu {
            width: 100px;
            height: 60px;
            border-radius: 10%;
        }

    </style>
</head>
<body>

<div class="container cus-container">
    <h3 class="text-center">线路信息列表</h3>

    <div>
        <!-- 搜索框div -->
        <div id="search-user" style="float: left; margin: 10px 0px;">
            <form class="form-inline"
                  action="${pageContext.request.contextPath}/route/selectRoute?currentPage=1&pageSize=${pageInfo.pageSize}" method="post">
                <div class="form-group">
                    <label for="exampleInputName1">线路名称:</label>
                    <input type="text" name="routeName" value="${routeBySelect.routeName}" class="form-control"
                           id="exampleInputName1" placeholder="请输入关键字" style="width: 120px">
                </div>
                &nbsp;&nbsp;&nbsp;
                <div class="form-group">
                    <label for="exampleInputName2">所属分类:</label>
                    <select name="routeTypeId" class="form-control" id="exampleInputName2">
                        <option value=""> -请选择分类-</option>
                        <c:forEach items="${types}" var="type">
                            <option value="${type.type_id}"  ${routeBySelect.routeTypeId == type.type_id ? "selected" : ""} >${type.type_name}</option>
                        </c:forEach>
                    </select>
                </div>
                &nbsp;&nbsp;&nbsp;
                <div class="form-group">
                    <label for="exampleInputName3">是否轮播:</label>
                    <select name="routeIsSlideshow" class="form-control" id="exampleInputName3">
                        <option value=""> -请选择是否轮播-</option>
                        <option value="1" ${routeBySelect.routeIsSlideshow == "1"? "selected" : ""} >是</option>
                        <option value="0" ${routeBySelect.routeIsSlideshow == "0"? "selected" : ""} >否</option>
                    </select>
                </div>
                &nbsp;&nbsp;&nbsp;
                <div class="form-group">
                    <label for="exampleInputName4">主题:</label>
                    <select name="routeThemeId" class="form-control" id="exampleInputName4">
                        <option value=""> -请选择主题-</option>
                        <c:forEach items="${themes}" var="theme">
                            <option value="${theme.theme_id}" ${routeBySelect.routeThemeId == theme.theme_id? "selected" : ""} >${theme.theme_name}</option>
                        </c:forEach>
                    </select>
                </div>
                &nbsp;&nbsp;&nbsp;
                <div class="form-group">
                    <label for="exampleInputName5">价钱:</label>
                    <input type="number" name="minPrice" value="${routeBySelect.minPrice}" class="form-control"
                           id="exampleInputName5" style="width: 100px">
                    -
                    <input type="number" name="maxPrice" value="${routeBySelect.maxPrice}" class="form-control"
                           style="width: 100px">
                </div>
                &nbsp;&nbsp;&nbsp;
                <div class="form-group">
                    <label for="exampleInputName6">供应商:</label>
                    <select name="supplierId" class="form-control" id="exampleInputName6">
                        <option value=""> -请选择分类-</option>
                        <c:forEach items="${suppliers}" var="supplier">
                            <option value="${supplier.supplier_id}" ${routeBySelect.supplierId == supplier.supplier_id? "selected" : ""} >${supplier.supplier_name}</option>
                        </c:forEach>
                    </select>
                </div>
                &nbsp;&nbsp;&nbsp;
                <div class="form-group">
                    <label for="exampleInputName7">是否删除:</label>
                    <select name="routeIsDeleted" class="form-control" id="exampleInputName7">
                        <option value=""> -请选择是否删除-</option>
                        <option value="1" ${routeBySelect.routeIsDeleted == "1"? "selected" : ""} >是</option>
                        <option value="0" ${routeBySelect.routeIsDeleted == "0"? "selected" : ""} >否</option>
                    </select>
                </div>

                &nbsp;&nbsp;
                <button type="submit" class="btn btn-default">查询</button>
            </form>
        </div>

        <!-- 添加、删除的按钮 -->
        <div style="float: right;margin: 10px 0px;">
            <a class="btn btn-primary" href="${pageContext.request.contextPath}/route/toAddRoute"
               target="myFrame">添加线路</a>
            <a class="btn btn-primary" onclick="dels()">删除选中</a>

        </div>
    </div>

    <table class="table table-bordered clearfix" id="user-list">
        <thead>
        <tr class="bg-primary">
            <th><input type="checkbox" id="firstCb"></th>
            <th>序号</th>
            <th>路线名称</th>
            <th>所属分类</th>
            <th>出发地</th>
            <th>目的地</th>
            <th>路线主图</th>
            <th>是否主题</th>
            <th>路线价格</th>
            <th>路线天数</th>
            <th>收藏数量</th>
            <th>供应商</th>
            <th>主题</th>
            <th>逻辑删除</th>
            <th>是否轮播</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${pageInfo.list}" var="route">
            <tr>
                <td><input type="checkbox" class="cb" value="${route.route_id}"></td>
                <td>${route.route_id}</td>
                <td>${route.route_name}</td>
                <td>${route.type.type_name}</td>
                <td>${route.route_departure_place}</td>
                <td>${route.route_destination}</td>
                <td><img src="<%=Res.mainFileUrl%>${route.routh_mainImage}" class="zhuTu"/></td>
                <td>${route.route_is_theme == "1"? "是" : "否"}</td>
                <td>${route.route_price}</td>
                <td>${route.route_day}</td>
                <td>${route.route_saveNumber}</td>
                <td>${route.supplier.supplier_name}</td>
                <td>${route.theme.theme_name}</td>
                <td>${route.routh_is_deleted == "1"? "是" : "否"}</td>
                <td>${route.routh_is_slideshow == "1"? "是" : "否"}</td>
                <td>
                    <c:if test="${aclUser.supplier.supplier_id != 0}">
                        <c:if test="${aclUser.supplier.supplier_id == route.route_supplierId}">
                            <a class="btn btn-default btn-sm"
                               href="${pageContext.request.contextPath}/route/toUpdateRoute?routeId=${route.route_id}">修改</a>
                            <a class="btn btn-default btn-sm"
                               href="${pageContext.request.contextPath}/route/softDeleteRoute?routeId=${route.route_id}">删除</a>
                            <a class="btn btn-default btn-sm"
                               href="${pageContext.request.contextPath}/image/toInsertImage?routeId=${route.route_id}">添加附图</a>
                        </c:if>
                    </c:if>
                    <c:if test="${aclUser.supplier.supplier_id == 0}">
                        <a class="btn btn-default btn-sm"
                           href="${pageContext.request.contextPath}/route/toUpdateRoute?routeId=${route.route_id}">修改</a>
                        <a class="btn btn-default btn-sm"
                           href="${pageContext.request.contextPath}/route/softDeleteRoute?routeId=${route.route_id}">删除</a>
                        <a class="btn btn-default btn-sm"
                           href="${pageContext.request.contextPath}/image/toInsertImage?routeId=${route.route_id}">添加附图</a>

                    </c:if>

                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <%--前五后四--%>

    <c:if test="${pageInfo.pages>=10}">
        <c:set var="begin" value="1"></c:set>
        <c:set var="end" value="10"></c:set>
        <c:if test="${pageInfo.pageNum>5}">
            <c:set var="begin" value="${pageInfo.pageNum-4}"></c:set>
            <c:set var="end" value="${pageInfo.pageNum+5}"></c:set>
        </c:if>
        <c:if test="${pageInfo.pageNum+5>pageInfo.pages}">
            <c:set var="begin" value="${pageInfo.pages-9}"></c:set>
            <c:set var="end" value="${pageInfo.pages}"></c:set>
        </c:if>
    </c:if>

    <c:if test="${pageInfo.pages<10}">
        <c:set var="begin" value="1"></c:set>
        <c:set var="end" value="${pageInfo.pages}"></c:set>
    </c:if>

    <!-- 分页导航 -->
    <div>
        <div class="form-inline" style="text-align: center">
            <div class="form-group">
                <a href="${pageContext.request.contextPath}/route/selectRoute?currentPage=1&pageSize=${pageInfo.pageSize}&routeName=${routeBySelect.routeName}&routeTypeId=${routeBySelect.routeTypeId}&routeIsSlideshow=${routeBySelect.routeIsSlideshow}&routeThemeId=${routeBySelect.routeThemeId}&minPrice=${routeBySelect.minPrice}&maxPrice=${routeBySelect.maxPrice}&supplierId=${routeBySelect.supplierId}&routeIsDeleted=${routeBySelect.routeIsDeleted}"
                   class="btn btn-default btn-sm">首页</a>
                <select class="form-control" name="pageSize" id="pageSize" onchange="ps(this.value)"
                        style="width: 120px">
                    <option value="2" ${pageInfo.pageSize == 2 ? "selected" : ""}>2页</option>
                    <option value="5" ${pageInfo.pageSize == 5 ? "selected" : ""}>5页</option>
                    <option value="10" ${pageInfo.pageSize == 10 ? "selected" : ""}>10页</option>
                    <option value="15" ${pageInfo.pageSize == 15 ? "selected" : ""}>15页</option>
                    <option value="20" ${pageInfo.pageSize == 20 ? "selected" : ""}>20页</option>
                </select>
                <a href="${pageContext.request.contextPath}/route/selectRoute?currentPage=${pageInfo.pages}&pageSize=${pageInfo.pageSize}&routeName=${routeBySelect.routeName}&routeTypeId=${routeBySelect.routeTypeId}&routeIsSlideshow=${routeBySelect.routeIsSlideshow}&routeThemeId=${routeBySelect.routeThemeId}&minPrice=${routeBySelect.minPrice}&maxPrice=${routeBySelect.maxPrice}&supplierId=${routeBySelect.supplierId}&routeIsDeleted=${routeBySelect.routeIsDeleted}"
                   class="btn btn-default btn-sm">尾页</a>
            </div>
        </div>
        <!-- 分页导航 页码-->
        <nav style="text-align: center">
            <ul class="pagination">
                <li>
                    <a href="${pageContext.request.contextPath}/route/selectRoute?currentPage=${pageInfo.prePage}&pageSize=${pageInfo.pageSize}&routeName=${routeBySelect.routeName}&routeTypeId=${routeBySelect.routeTypeId}&routeIsSlideshow=${routeBySelect.routeIsSlideshow}&routeThemeId=${routeBySelect.routeThemeId}&minPrice=${routeBySelect.minPrice}&maxPrice=${routeBySelect.maxPrice}&supplierId=${routeBySelect.supplierId}&routeIsDeleted=${routeBySelect.routeIsDeleted}">&laquo;</a>
                </li>

                <c:forEach begin="${begin}" end="${end}" var="page">
                    <li ${page eq pageInfo.pageNum?"class='active'":''}>
                        <a href="${pageContext.request.contextPath}/route/selectRoute?currentPage=${page}&pageSize=${pageInfo.pageSize}&routeName=${routeBySelect.routeName}&routeTypeId=${routeBySelect.routeTypeId}&routeIsSlideshow=${routeBySelect.routeIsSlideshow}&routeThemeId=${routeBySelect.routeThemeId}&minPrice=${routeBySelect.minPrice}&maxPrice=${routeBySelect.maxPrice}&supplierId=${routeBySelect.supplierId}&routeIsDeleted=${routeBySelect.routeIsDeleted}">${page}</a>
                    </li>
                </c:forEach>

                <li>
                    <a href="${pageContext.request.contextPath}/route/selectRoute?currentPage=${pageInfo.nextPage}&pageSize=${pageInfo.pageSize}&routeName=${routeBySelect.routeName}&routeTypeId=${routeBySelect.routeTypeId}&routeIsSlideshow=${routeBySelect.routeIsSlideshow}&routeThemeId=${routeBySelect.routeThemeId}&minPrice=${routeBySelect.minPrice}&maxPrice=${routeBySelect.maxPrice}&supplierId=${routeBySelect.supplierId}&routeIsDeleted=${routeBySelect.routeIsDeleted}">&raquo;</a>
                </li>
            </ul>
        </nav>
        <div style="float: right;">
            <span>当前第<b>${pageInfo.pageNum}</b>页 共<b>${pageInfo.pages}</b>页 共<b>${pageInfo.total}</b>条数据</span>
        </div>

    </div>
</div>


</body>
</html>
<script>
    function ps(pageSize) {
        window.location.href = "${pageContext.request.contextPath}/route/selectRoute?currentPage=1&pageSize=" + pageSize + "&routeName=${routeBySelect.routeName}&routeTypeId=${routeBySelect.routeTypeId}&routeIsSlideshow=${routeBySelect.routeIsSlideshow}&routeThemeId=${routeBySelect.routeThemeId}&minPrice=${routeBySelect.minPrice}&maxPrice=${routeBySelect.maxPrice}&supplierId=${routeBySelect.supplierId}&routeIsDeleted=${routeBySelect.routeIsDeleted}";
    }

    function dels() {
        let checkeds = $("input[class='cb']:checked");
        let routeIds = "";
        for (let i = 0; i < checkeds.length; i++) {
            console.log(checkeds[i].value)
            routeIds += checkeds[i].value + ",";
        }
        if (confirm("确定删除吗？")) {
            window.location.href = "${pageContext.request.contextPath}/route/deleteRoutes?routeIds=" + routeIds;
        }
    }

</script>